Skip to content

build(test): wire every test suite into the build and run it in CI - #8

Merged
devnullexile merged 1 commit into
mainfrom
fix/ci-run-tests
Oct 12, 2026
Merged

devnullexile merged 1 commit into
mainfrom
fix/ci-run-tests

Conversation

@devnullexile

@devnullexile devnullexile commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Closes #3.

Problem

CI never executed a test. LLVM was built with LLVM_INCLUDE_TESTS=OFF, so unittests/ returned early when LLVMTestingSupport was missing, the build step hid that behind || true, PseudoModuleTests (72 tests) was never compiled, and test/, fuzzer/ and benchmarks/ were not referenced from the root CMake and linked target names that no longer exist.

Changes

  • cmake/LLVMTestingLibs.cmake: builds llvm_gtest, llvm_gtest_main, LLVMTestingSupport and LLVMTestingAnnotations from an llvm-project source tree when the LLVM package does not export them. The tree is derived from CLANGD_INCLUDE_DIRS or set with PSEUDO_LLVM_SOURCE_DIR. PSEUDO_ENABLE_TESTS defaults to ON when these dependencies are found and OFF otherwise, so a plain configure still builds the plugin; with tests ON, a missing dependency is a configure error instead of a silent skip.
  • Module objects shared with the test: the plugin sources compile once into obj.clangd_pseudo, linked by both clangd_pseudo (MODULE) and PseudoModuleTests. The test also compiles clangd's own scaffolding (TestFS, TestTU, SyncAPI, LSPClient, TestIndex, Annotations) and gets a Features.inc, reused from the LLVM build tree when present and configured from the template otherwise.
  • clangd/PluginSymbols.cpp: the definitions that exist only because the plugin is loaded into an unmodified clangd (Windows fallbacks for LSPError::ID, DefaultRankingModel, charinfo::InfoTable; the weak ErrorInfoBase typeinfo; the ABI-check variable) move out of PseudoModule.cpp into a file compiled only into the MODULE target. Linked next to the real clangDaemon.lib they were duplicate definitions. They are plain definitions rather than selectany, since /Zc:inline drops COMDAT data that nothing in the same translation unit references.
  • test/, fuzzer/, benchmarks/ are wired into the root build, with target names corrected. The fuzzer builds with the tests (the lit suite uses it) or on its own with PSEUDO_ENABLE_FUZZER; benchmarks are behind PSEUDO_ENABLE_BENCHMARKS. Lit runs from the source tree's lit.py; LLVM_RUNTIME_OUTPUT_INTDIR is set so the lit config can find built tools. Python is found once at the root, because add_lit_target builds its command from Python3_EXECUTABLE and find_package results are directory-scoped.
  • Link order: the clang libraries follow the Pseudo libraries on the test link lines, as tool/CMakeLists.txt already does, since libPseudo.a uses clang::Lexer and GNU ld resolves static archives in a single pass.
  • PseudoModuleTests fixes against unmodified clangd (four tests encoded behaviour only a forked clangd could satisfy):
    • the registry test checks the registry entry and iterates fromRegistry(), since upstream's untyped add makes get<>() unreachable;
    • five ClangdServer-driven tests call setFSForTesting, as seventeen sibling tests already do;
    • one assertion expecting clangd to skip its AST build in pseudo-only mode is removed (this is the Plugin overrides clangd's own LSP handlers, so no Clang AST is ever built #2 design mismatch surfacing);
    • the two source-parsing tests take the llvm-project path from the build.
  • CI: builds FileCheck, not, count and LLVMFuzzerCLI as part of the cached clangd build (cache key v2), runs ninja check-clang-pseudo on Linux, macOS and Windows, removes || true and the skip branch, enables tests on Windows. CLANGD_INCLUDE_DIRS is normalized to a CMake-style path, since a native Windows path with backslashes is re-parsed as escape sequences by LLVM's macro-based add_unittest.
  • README: corrected build/test commands, documented the test dependencies and options.

Verification

Local, against Homebrew LLVM 23.1.0 with llvmorg-23.1.0 sources, from a clean build directory:

Target Before After
ClangPseudoTests unknown target 46 pass
PseudoModuleTests unknown target, never compiled 72 pass
check-clang-pseudo unknown target 148 pass (30 lit cases + both gtest binaries)

Also checked: configuring without an llvm-project tree fails with a clear message, and -DPSEUDO_ENABLE_TESTS=OFF still configures.

On CI, each platform's check-clang-pseudo step prints the lit summary with the test count, so a job is green only when the suite ran.

@devnullexile
devnullexile force-pushed the fix/ci-run-tests branch 2 times, most recently from 0fc03e3 to ca6d076 Compare October 11, 2026 16:44

@DrSergei DrSergei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Configure hard-fails by default when test deps are missing (behavior change) — PSEUDO_ENABLE_TESTS defaults ON, and cmake/LLVMTestingLibs.cmake:26 now FATAL_ERRORs if the LLVM package doesn't export testing libs. A plain cmake -B build against a distro LLVM without LLVMTestingSupport (and no -DPSEUDO_LLVM_SOURCE_DIR) now fails configure instead of skipping tests. Likely intentional (README notes it), but tests ON by default makes the plugin-only path fail. Consider defaulting tests OFF, or only hard-erroring when tests were explicitly requested.
  2. PSEUDO_ENABLE_FUZZER is cached and won't track PSEUDO_ENABLE_TESTS — derived default in CMakeLists.txt:106, but option() caches on first configure. Reconfiguring a build dir from tests ON → OFF leaves the fuzzer ON, still adding fuzzer (which links LLVMFuzzerCLI). Fresh dirs unaffected; gate the subdirectory on both options or drop the derived default.
  3. charinfo::InfoTable fallback still uses selectany — the same /Zc:inline COMDAT-dropping mechanism the commit fixed for LSPError::ID/CodeCompleteOptions::DefaultRankingModel also applies to PluginSymbols.cpp:67. If the reported unresolved externals were accurate this is fine, but worth confirming it isn't a third Windows plugin link error. (Unverifiable without an MSVC build.)
  4. CI caches the LLVM tree before building test utilities (minor) — "Build LLVM test utilities" runs after "Save Clangd cache" in all three jobs (ci.yml:71–81, 191–201, 319–330), so FileCheck/not/count/LLVMFuzzerCLI get rebuilt every run. Correct, just wasted work; reorder or bump the cache key.

@devnullexile

Copy link
Copy Markdown
Member Author

Thanks for the careful read, all four points were on target. Addressed in the updated commit:

  1. Hard-fail by default — agreed, that broke the plugin-only path. PSEUDO_ENABLE_TESTS now defaults to ON only when the dependencies are discoverable (an exported LLVMTestingSupport, or an llvm-project tree via PSEUDO_LLVM_SOURCE_DIR / CLANGD_INCLUDE_DIRS), and to OFF otherwise with a status message saying how to enable them. With tests ON, a missing dependency is still a configure error. Checked locally: plain configure against Homebrew LLVM with no tree now succeeds with tests off; -DPSEUDO_ENABLE_TESTS=ON in the same setup fails with the message.

  2. Cached fuzzer default — right, option() would freeze the derived value. The fuzzer directory is now added when PSEUDO_ENABLE_TESTS OR PSEUDO_ENABLE_FUZZER, and PSEUDO_ENABLE_FUZZER defaults to OFF with the meaning "build it even without tests". Reconfiguring tests ON → OFF drops the fuzzer along with them.

  3. InfoTable selectany — the final Windows run linked and ran all 148 tests with it still selectany, so it was not a third unresolved external in practice. I could not pin down why that one survived /Zc:inline when the two class statics did not, so I switched it to an ordinary definition as well rather than keep a fallback that depends on an incidental reference. The plugin links with /FORCE:MULTIPLE and the symbol is not exported from clangd.exe (that is why the fallback exists), so there is nothing for it to clash with.

  4. Cache ordering — the test utilities are now built in the same step as clangd (ninja -C llvm-build clangd FileCheck not count LLVMFuzzerCLI) and the cache keys are bumped to v2 so the saved trees include them. Because restore-keys still matches the v1 prefix, the next run restores the old tree and builds only the missing tools before saving v2, so it should not be a cold rebuild. The separate "Build LLVM test utilities" step stays as a no-op safety net for any cache saved without them.

@devnullexile
devnullexile force-pushed the fix/ci-run-tests branch 2 times, most recently from 4bb3582 to de59706 Compare October 11, 2026 16:57
@devnullexile

Copy link
Copy Markdown
Member Author

Follow-up on point 4: the first run after the key bump showed the cache fallback path had never actually worked. restore-keys hands back the old tree without an exact cache-hit, so the checkout step ran git clone into an existing directory. That step now reuses a restored llvm-project when one is present, and the run on the current commit went through the intended path on all three platforms: restored v1, built only the four missing tools, ran the full suite (148/148 everywhere), and saved v2.

@DrSergei DrSergei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. PSEUDO_ENABLE_TESTS can default ON then hard-fail on missing clangDaemon — medium
    CMakeLists.txt:117-118 enables tests by default when LLVMTestingSupport exists or an llvm-project tree is found, but never checks for the clangDaemon target. unittests/CMakeLists.txt:41-47 turns a missing clangDaemon into FATAL_ERROR.
    Realistic path: CLANGD_INCLUDE_DIRS points inside a source checkout (so the plugin builds), which auto-derives PSEUDO_LLVM_SOURCE_DIR at CMakeLists.txt:83-84 → tests default ON. If the find_package LLVM/Clang is a distro/Homebrew package that does not export clangDaemon, a plain configure now aborts. This contradicts the comment at CMakeLists.txt:113-116 ("a plain configure ... still builds the plugin") and regresses the prior if(TARGET clangDaemon) silent skip. Fix: add the clangDaemon condition to the default check, or downgrade the missing-target case to a warning/skip.
  2. PSEUDO_LLVM_SOURCE_DIR embedded in a C++ literal without normalization — low (Windows only)
    CMakeLists.txt:83-84 normalizes auto-derived paths via get_filename_component(... ABSOLUTE), but a user/env-supplied path (CMakeLists.txt:82) is not normalized. It is pasted into a string literal at unittests/clangd/CMakeLists.txt:93. On Windows, -DPSEUDO_LLVM_SOURCE_DIR="C:\llvm-project" produces invalid escape sequences (\l, \p), corrupting the value used by findRepoSourceFile. Affects only users who set the variable explicitly on Windows; run it through get_filename_component(... ABSOLUTE) or file(TO_CMAKE_PATH ...) first.

Overall, LGTM

@ArcsinX ArcsinX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Review Findings

Thanks for wiring all the test suites and enabling CI testing across platforms. The CI configuration and object library decoupling look very solid.

However, there are several configure regressions and portability issues that need to be addressed before merging (so withholding approval for now):

  1. Configure Hard-Fail on Missing clangDaemon (CMakeLists.txt:118 & unittests/CMakeLists.txt:42):

    • PSEUDO_ENABLE_TESTS defaults to ON whenever PSEUDO_LLVM_SOURCE_DIR is set or auto-detected (e.g. when CLANGD_INCLUDE_DIRS points inside an llvm-project checkout).
    • If building against an installed LLVM distribution package (such as Homebrew LLVM or distro packages), clangDaemon is not exported.
    • unittests/CMakeLists.txt:42 raises a FATAL_ERROR, breaking standard plugin builds (cmake -B build) and regressing the previous graceful if(TARGET clangDaemon) behavior.
    • Recommendation: Check for TARGET clangDaemon when computing PSEUDO_ENABLE_TESTS_DEFAULT or downgrade unittests/CMakeLists.txt:42 to skip PseudoModuleTests with a status message while still allowing ClangPseudoTests and lit tests to build.
  2. Unescaped Windows Path in C++ String Literal (CMakeLists.txt:88 & unittests/clangd/CMakeLists.txt:93):

    • Unlike CLANGD_INCLUDE_DIRS which is normalized via get_filename_component(... ABSOLUTE), PSEUDO_LLVM_SOURCE_DIR is not normalized when provided via -DPSEUDO_LLVM_SOURCE_DIR=... or $ENV{PSEUDO_LLVM_SOURCE_DIR}.
    • In unittests/clangd/CMakeLists.txt:93, it is passed directly into target_compile_definitions(PseudoModuleTests PRIVATE PSEUDO_LLVM_SOURCE_DIR="${PSEUDO_LLVM_SOURCE_DIR}").
    • On Windows, raw backslashes expand into invalid escape sequences (e.g., \l, ) inside PseudoModuleTests.cpp:3164, leading to compilation errors or corrupted path lookups.
    • Recommendation: Normalize PSEUDO_LLVM_SOURCE_DIR with get_filename_component(PSEUDO_LLVM_SOURCE_DIR "${PSEUDO_LLVM_SOURCE_DIR}" ABSOLUTE) after discovery.
  3. target_include_directories(... PUBLIC ...) on IMPORTED Targets (cmake/LLVMTestingLibs.cmake:59):

    • In pseudo_require_llvm_testing_libs(), target_include_directories(${target} PUBLIC ...) will fail with a fatal CMake error if LLVMTestingSupport was already an imported target from the LLVM package (CMake forbids PUBLIC/PRIVATE on imported targets).
    • Recommendation: Only set include directories for targets in missing that were built from source in this function.
  4. Hard FATAL_ERROR for Clangd Test Support Sources (unittests/clangd/CMakeLists.txt:20):

    • If CLANGD_INCLUDE_DIRS points to clangd headers from an installation without unittests/ test sources, the build hard-fails.
    • Recommendation: Gracefully skip PseudoModuleTests instead of aborting the entire build.
  5. file(GLOB_RECURSE) on Static File Paths (unittests/clangd/CMakeLists.txt:31):

    • Uses GLOB_RECURSE on static paths. When LLVM_BINARY_DIR is empty in standalone builds, this checks root paths /tools/.... Use if(EXISTS ...) instead.
  6. Missing -fno-rtti / /GR- on clangd_pseudo MODULE Target (clangd/CMakeLists.txt:53):

    • target_compile_options(... PRIVATE -fno-rtti) was applied only to obj.clangd_pseudo. The MODULE target clangd_pseudo compiles PluginSymbols.cpp with RTTI enabled, causing a mismatch with LLVM and the rest of the plugin.
  7. Literal @SHLIBDIR@ and @LLVM_LIBS_DIR@ in Test Shim (test/Unit/lit.cfg.py:18-20):

    • (Existing file, not touched in this PR) test/Unit/lit.cfg.py sets config.environment[shlibpath_var] using literal string "@SHLIBDIR@" and "@LLVM_LIBS_DIR@" instead of config.shlibdir and config.llvm_libs_dir. Consider fixing this in a follow-up or along with this PR.

Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
Comment thread unittests/CMakeLists.txt Resolved
Comment thread cmake/LLVMTestingLibs.cmake Resolved
Comment thread unittests/clangd/CMakeLists.txt Resolved
Comment thread unittests/clangd/CMakeLists.txt Resolved
Comment thread clangd/CMakeLists.txt Resolved
CI never executed a test: LLVM was built with LLVM_INCLUDE_TESTS=OFF, so
unittests/ skipped itself when LLVMTestingSupport was missing, the build
step hid that behind `|| true`, PseudoModuleTests was never compiled, and
test/, fuzzer/ and benchmarks/ were not referenced from the root CMake and
linked target names that no longer exist.

- Add cmake/LLVMTestingLibs.cmake: build llvm_gtest, llvm_gtest_main,
  LLVMTestingSupport and LLVMTestingAnnotations from an llvm-project source
  tree (PSEUDO_LLVM_SOURCE_DIR, derived from CLANGD_INCLUDE_DIRS) when the
  LLVM package does not export them. PSEUDO_ENABLE_TESTS defaults to ON
  when these dependencies are found and OFF otherwise, so a plain configure
  still builds the plugin; with tests ON, a missing dependency is a
  configure error instead of a silent skip.
- Compile the module sources into obj.clangd_pseudo, shared by the plugin
  and PseudoModuleTests, and build PseudoModuleTests with clangd's own test
  scaffolding (TestFS, TestTU, SyncAPI, LSPClient, TestIndex, Annotations)
  and a generated Features.inc.
- Move the definitions that exist only because the plugin is loaded into an
  unmodified clangd (Windows fallbacks for LSPError::ID, DefaultRankingModel
  and charinfo::InfoTable, the weak ErrorInfoBase typeinfo, the ABI-check
  variable) into clangd/PluginSymbols.cpp, compiled only into the MODULE
  target; linked next to the real clangDaemon.lib they were duplicate
  definitions. They are plain definitions, not selectany: /Zc:inline drops
  COMDAT data unreferenced in its translation unit.
- Wire test/ (lit, run from the source tree's lit.py), fuzzer/ and
  benchmarks/ into the root build. The fuzzer builds with the tests (the
  lit suite uses it) or with PSEUDO_ENABLE_FUZZER on its own. Set
  LLVM_RUNTIME_OUTPUT_INTDIR so the lit config can find built tools. Find
  Python once at the root: add_lit_target builds its command from
  Python3_EXECUTABLE, which a find_package inside tool/ left unset in
  test/, so Windows ran lit.py through the file association, detached,
  and reported success without running anything.
- Order the clang libraries after the Pseudo libraries on the test link
  lines, as tool/CMakeLists.txt already does: libPseudo.a uses clang::Lexer
  and GNU ld resolves static archives in a single pass.
- Fix PseudoModuleTests against unmodified clangd: the registry test checks
  the registry entry and iterates fromRegistry() (which uses the untyped
  add, so get<>() can never find the module); ClangdServer-driven tests
  point the module at the mock file system like their siblings do; the
  pseudo-only test no longer expects clangd to skip its AST build; the
  source-parsing tests take the llvm-project path from the build; a path
  comparison normalizes separators for Windows.
- CI: build FileCheck, not, count and LLVMFuzzerCLI as part of the cached
  clangd build (cache key v2), run `ninja check-clang-pseudo` on Linux,
  macOS and Windows, remove `|| true` and the skip branch, enable tests on
  Windows. Normalize CLANGD_INCLUDE_DIRS to a CMake-style path: a native
  Windows path with backslashes is re-parsed as escape sequences by LLVM's
  macro-based add_unittest.
- README: correct the build/test commands and document the test
  dependencies and the new options.

Verified locally against Homebrew LLVM 23.1.0 with llvmorg-23.1.0 sources:
check-clang-pseudo runs 148 tests (30 lit cases, ClangPseudoTests 46,
PseudoModuleTests 72), all passing.
@devnullexile

Copy link
Copy Markdown
Member Author

Second round addressed in the updated commit (still a single commit):

  • Tests defaulting ON no longer hard-fail on a missing clangDaemon: PseudoModuleTests checks its own prerequisites and is skipped with a status message, while ClangPseudoTests and the lit suite still build. CI builds PseudoModuleTests explicitly so a skip cannot pass there.
  • PSEUDO_LLVM_SOURCE_DIR is normalized after discovery, covering -D and environment values before it lands in the compile definition.
  • The testing-library include directory is only attached to targets built from source, never to an imported one.
  • Features.inc lookup uses exact if(EXISTS) checks; a missing template feeds the skip logic.
  • -fno-rtti / /GR- is set on the MODULE target too (the global option already covered it).
  • The lit shim in test/Unit/lit.cfg.py now uses config.shlibdir and config.llvm_libs_dir instead of the literal placeholders.

Local run: 148/148 on the full suite, plus the skip path verified by configuring against a clangd tree without unittests/.

@ArcsinX ArcsinX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! All previous review comments have been properly addressed, the configure fallback/skip logic is clean and robust, and the test suite passes across Linux, macOS, and Windows.

@ArcsinX ArcsinX removed their assignment Oct 12, 2026

@bahbyega bahbyega left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@devnullexile
devnullexile merged commit 5907299 into main Oct 12, 2026
4 checks passed
@devnullexile
devnullexile deleted the fix/ci-run-tests branch October 12, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI runs no unit, module, or lit tests; test build failures are swallowed

4 participants